package com.lei.demo.service.imp;

import com.lei.demo.dao.TripFormDAO;
import com.lei.demo.entity.TripForm;
import com.lei.demo.service.TripFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Shinelon on 2017/6/15.
 */
@Service("TripFormService")
@Transactional(readOnly = true)
public class TripFormServiceImpl implements TripFormService {

    @Autowired
    TripFormDAO tripFormDAO;

    @Override
    @Transactional(readOnly = false)
    public void delete(int trid) {
        tripFormDAO.delete(trid);
    }

    @Override
    public List<TripForm> findAllTripForms() {
        return tripFormDAO.getAllTripForms();
    }

    @Override
    public List<TripForm> findAllTripForms(int trid) {
        return tripFormDAO.findTripFormAll(trid);
    }

    @Override
    public List<TripForm> findTripForms(int trid) {
        return tripFormDAO.findTripForm(trid);
    }

    @Override
    public List<TripForm> findTripForms(String username) {
        return tripFormDAO.findTripForm(username);
    }

    @Override
    public TripForm findById(int trid) {
       List<TripForm> tripForms = findTripForms(trid);
       if(!tripForms.isEmpty()) {
           return tripForms.get(0);
       } else {
           return null;
       }
    }

    @Override
    @Transactional(readOnly = false)
    public void save(TripForm tripForm) {
        tripFormDAO.save(tripForm);
    }

    @Override
    public void update(TripForm tripForm) {
        tripFormDAO.update(tripForm);
    }

}
